<?php
if (isset($_REQUEST['action'])) 
{
	switch ($_REQUEST['action']) 
	{
		case 'Sign In':
			if((($_POST['u_email']=="") and ($_POST['u_pass']=="")) or (($_POST['u_email']=="") or ($_POST['u_pass']=="")))
			{
				header("Location: index.php?empty");
				exit();
			}
			if(!preg_match("/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-z]{2,3})$/", $_POST['u_email']))
			{
				header('Location: index.php?wrong');
				exit();
			}
			else 
			{
				$Email = htmlspecialchars($_POST['u_email']);
				$Pass = htmlspecialchars($_POST['u_pass']);

				try {
					require 'core/class.userprofile.php';	
					$obj = new UserProfile();
					if($obj->_makeConnection()->_selectDB()->_userLogin($Email, $Pass))
					{
						header('Location: welcome.php');
						exit();
					}
					else
					{
						header('Location: index.php');
						exit();
					}
				}
				catch(Exception $e) {
					echo $e->getMessage();
				}
			}
			break;

		case 'Logout':
			try {
				require 'core/class.userprofile.php';	
				UserProfile::_userLogout();
			}
			catch(Exception $e) {
				echo $e->getMessage();
			}
			break;
		}
}
?>